//
//  ProfileHeaderView.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2020/2/28.
//  Copyright © 2020 tao Tao. All rights reserved.
//

import UIKit

protocol ProfileHeaderViewDelegate: NSObjectProtocol {
    func headerView(allOrderDidTapped view: ProfileHeaderView, type: YSGDiagnoseType)
    func headerView(firstDidTapped view: ProfileHeaderView, type: YSGDiagnoseType)
    func headerView(secondDidTapped view: ProfileHeaderView, type: YSGDiagnoseType)
    func headerView(thirdDidTapped view: ProfileHeaderView, type: YSGDiagnoseType)
    func headerView(fourthDidTapped view: ProfileHeaderView, type: YSGDiagnoseType)
}

class ProfileHeaderView: UIView {
    
    weak var delegate: ProfileHeaderViewDelegate?
    
    private var type: YSGDiagnoseType = .advisory {
        didSet {
            //hideCountLabel()
            updateData(with: viewModel)
        }
    }
    private var viewModel = ProfileViewModel(datas: [])
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        makeUI()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        makeUI()
    }
    
    // MARK: - 图文咨询、云门诊

    @IBOutlet private weak var diagnoseFirstBtn: ProfileItemButton!

    @IBOutlet private weak var diagnoseSecondBtn: ProfileItemButton!

    @IBOutlet private weak var diagnoseThirdBtn: ProfileItemButton!

    @IBOutlet private weak var diagnoseFourthBtn: ProfileItemButton!
    
  

    
    @objc private func allOrderAction() {
        delegate?.headerView(allOrderDidTapped: self, type: type)
    }
    
    @IBAction private func firstClickedAction() {
        delegate?.headerView(firstDidTapped: self, type: type)
    }
    
    @IBAction private func secondClickedAction() {
        delegate?.headerView(secondDidTapped: self, type: type)
    }
    
    @IBAction private func thirdClickedAction() {
        delegate?.headerView(thirdDidTapped: self, type: type)
    }
    
    @IBAction private func fourthClickedAction() {
        delegate?.headerView(fourthDidTapped: self, type: type)
    }

}

extension ProfileHeaderView {
    private func makeUI() {
        layer.cornerRadius = 16
        layer.masksToBounds = true
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(allOrderAction))
        addGestureRecognizer(tap)
    }
    
    private func clickedConsultation() {
        type = .advisory

    }
    
    private func clickedCloud() {
        type = .cloud

    }
}

extension ProfileHeaderView {
 
    
    func configure(with viewModel: ProfileViewModel) {
        self.viewModel = viewModel
        updateData(with: viewModel)
    }
    
    private func updateData(with viewModel: ProfileViewModel) {
        switch type {
        case .advisory:
            _ = viewModel.datas.map {
                if $0.orderType == 1 { // 图文咨询

                }
            }
        case .cloud:
            _ = viewModel.datas.map {
                if $0.orderType == 3 { // 云门诊

                }
            }
        default: break
        }
    }

}
